package com.uchedao.seller.ui.car.order;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.google.gson.JsonObject;
import com.uchedao.seller.R;
import com.uchedao.seller.config.Api;
import com.uchedao.seller.config.GlobalInfo;
import com.uchedao.seller.http.request.HttpRequest;
import com.uchedao.seller.manager.UserInfoManager;
import com.uchedao.seller.ui.car.base.TabBaseFragment;
import com.uchedao.seller.util.T;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by hang on 2015/10/23.
 * 手续办理中车辆
 */
public class ProcedureFragment extends TabBaseFragment implements View.OnClickListener {

    @Override
    protected String getActivityTag() {
        return "ProcedureFragment";
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mRoot = inflater.inflate(R.layout.fragment_procedure, container, false);
        initView();
        return mRoot;
    }

    public void initView() {
        mRoot.findViewById(R.id.login).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch(view.getId()) {
            case R.id.login:
                login();
                break;
        }
    }

    public void login() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("mobile", "13960864746");
        map.put("password", "123123");
        map.put("app_name", GlobalInfo.APP_NAME);
        map.put("registration_id", "");
        Request request = HttpRequest.getRequest(HttpRequest.POST, Api.Action.USER_LOGIN, map
                , new Response.Listener<JsonObject>() {
            @Override
            public void onResponse(JsonObject response) {
                T.showShort(getActivity(), response.get("passport").getAsString());
                UserInfoManager.saveSTATE(true);
                UserInfoManager.savePASS_PORT(response.get("passport").getAsString());
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                T.showShort(getActivity(), error.getMessage());
            }
        }, false);
        addQueue(request);
    }
}
